package io.renren.controller;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import io.renren.common.utils.AES128Util;
import io.renren.common.utils.HttpResult;
import io.renren.common.utils.HttpUtils;
import org.apache.commons.codec.digest.DigestUtils;

/**
 * @author lizhi
 * @Date:2019/8/13 15:13
 */
public class DemoCreateOrder {
    public static void main(String[] args) throws Exception {
      /*  merchantid="80000022";//商户编码
        md5key="da1dafd719a3bd1d";
        aeskey="AACEC36A5E1E0787";*/


        String merchantid = "80000109";
        String md5key = "13677c50549b4da5";
        String aeskey = "5D71F6445CDD109F";
        String apiurl = "http://127.0.0.1:8004/api/createQrOrder";

        Long timestamp = System.currentTimeMillis();//加密时间戳
        String sign = DigestUtils.md5Hex(merchantid + timestamp + md5key);
        JSONObject reqdata = new JSONObject(true);
        reqdata.put("orderchannel", "1");
        reqdata.put("applyamount", "2");
        reqdata.put("username", "李涛");
        reqdata.put("bankname", "建设");
        reqdata.put("merchantorderid", System.currentTimeMillis());
        reqdata.put("recaccount", "15594980703");
        reqdata.put("callbackurl", "http://127.0.0.1:8004/api/rrPayCallBack");
        System.out.println(reqdata);
        String data = AES128Util.encryptBase64(reqdata.toJSONString(), aeskey);
        System.out.println(data);
        JSONObject reqobj = new JSONObject();
        reqobj.put("merchantid", merchantid);
        reqobj.put("timestamp", timestamp);
        reqobj.put("sign", sign);
        reqobj.put("data", data);
        System.err.println("商户请求参数:" + reqobj);
        HttpResult result = HttpUtils.doPostJson(apiurl, reqobj.toJSONString());
        if (200 == result.getCode()) {
            System.err.println("订单创建返回参数:" + result.getBody());
            //{"code":0,"msg":"success","data":{"applyamount":100,"orderid":"2019042516065332845","payurl":"weixin://wap/pay?prepayid%3Dwx051043094235538274e763141514228532&package=4029845407&noncestr=1572921789&sign=b59ac548503a971599022373b7fef79f","payamount":100.0}}
            JSONObject resobj = JSON.parseObject(result.getBody());
            JSONObject dataobj = resobj.getJSONObject("data");
            System.err.println("返回二维码信息:" + dataobj);

        } else {
            System.err.println("创建订单失败");
        }
    }
}
